package com.itheima.jdbc.homework;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

//- 查询：查询所有数据
//- 添加：添加品牌
//- 修改：根据id修改
//- 删除：根据id删除
public class Test1 {
    public static void main(String[] args) throws SQLException {
        //- 查询：查询所有数据
        Connection connection = Connectionpoor.getConnection();
        ArrayList<Brand> al=new ArrayList<>();
        String sql="select * from tb_brand";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String brand_name = resultSet.getString("brand_name");
            String company_name = resultSet.getString("company_name");
            int ordered = resultSet.getInt("ordered");
            String description = resultSet.getString("description");
            int status = resultSet.getInt("status");
            Brand brand = new Brand(id, brand_name, company_name, ordered, description, status);
            al.add(brand);
        }
        resultSet.close();
        preparedStatement.close();
        connection.close();
        for (Brand brand : al) {
            System.out.println(brand);
        }

    }
}
